package com.mdp.im.core.subscriber.action.impl.msgaction;

import com.alibaba.fastjson.JSONObject;
import com.mdp.im.core.scbscriber.api.action.GroupMsgAction;
import com.mdp.im.core.service.admin.BlackUserGroupsService;
import com.mdp.im.core.service.admin.GroupAdminService;
import com.mdp.im.core.utils.msg.MsgAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("subscriber.GroupMsgActionAction")
/**
 * msgId:xxxx,
 * groupId:xxxxx,
 * msgType:group,
 * action:newMessage,
 * sendUserid:xxx,
 * toUserid:xxxxx, 
 * msgAction: forbiddenGroupWords/forbiddenUserWords/forbiddenJoin/allowGroupWords/allowUserWords/allowJoin/ 全群禁言/禁言一个用户/禁止加人/允许发言/允许某个人发言/允许加人
 * 
 * @author qqkj
 *
 */
public class GroupAdminMsgAction implements GroupMsgAction {

	@Autowired
	GroupAdminService groupAdminService;

	@Autowired
	BlackUserGroupsService blackUserGroupsService;
	
	@Override
	public void doAction(JSONObject message) {
		String msgAction=message.getString("msgAction");
		String sendUserid=message.getString("sendUserid");
		String toUserid=message.getString("toUserid");
		Long millSec=message.getLong("millSec");
		String groupId=message.getString("groupId");
		if(MsgAction.group_forbiddenGroupWords.equals(msgAction)) {
			groupAdminService.forbiddenGroupWords(groupId, millSec);
		}else if(MsgAction.group_forbiddenJoin.equals(msgAction)) {
			groupAdminService.forbiddenJoin(groupId, millSec);
		}if(MsgAction.group_forbiddenUserWords.equals(msgAction)) {
			blackUserGroupsService.putBlack(toUserid, groupId, millSec);
		}if(MsgAction.group_allowGroupWords.equals(msgAction)) {
			groupAdminService.allowGroupWords(groupId);
		}if(MsgAction.group_allowUserWords.equals(msgAction)) {
			blackUserGroupsService.removeBlack(toUserid, groupId);
		}if(MsgAction.group_allowJoin.equals(msgAction)) {
			groupAdminService.allowJoin(groupId);
		} 
	}

	@Override
	public boolean suportMsgAction(String msgAction) {
		// TODO Auto-generated method stub
		return MsgAction.group_forbiddenGroupWords.equals(msgAction)|| MsgAction.group_forbiddenJoin.equals(msgAction)|| MsgAction.group_forbiddenUserWords.equals(msgAction)
				|| MsgAction.group_allowGroupWords.equals(msgAction)|| MsgAction.group_allowUserWords.equals(msgAction)|| MsgAction.group_allowJoin.equals(msgAction);
	}

}
